package com.xunfang.controller;

import com.xunfang.bean.Result;
import com.xunfang.bean.User;
import com.xunfang.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yellow Docter
 * @date 2023 -10-17
 * @desc
 */
@RestController
@RequestMapping("user")
@Api(tags = "用户管理模块...")   //controller的描述
public class UserController {

    @Autowired
    private IUserService userService;

    @GetMapping("{id}")
    @ApiOperation("通过id 查询 用户信息...")
    public Result findUserById(@PathVariable Integer id){
        User user = userService.findUserById(id);
        return Result.ok(user);
    }

    @PostMapping
    @ApiOperation("添加用户信息...")
    public Result addUser(@RequestBody User user){

        userService.addUser(user);

        return Result.ok("添加成功...");
    }

    @DeleteMapping("{id}")
    @ApiOperation("通过id删除用户信息...")
    public Result deleteUserById(@PathVariable Integer id){
        userService.deleteUserById(id);
        return  Result.ok("删除成功...");
    }

    @GetMapping("/{currentPage}/{pageSize}")
    @ApiOperation("分页查询")
    public Result pageUsers(
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize){
        //分页的业务
        List<User> data = userService.pageUsers(currentPage,pageSize);
        return Result.ok(data);
    }

    @GetMapping("/plus/{currentPage}/{pageSize}")
    @ApiOperation("使用分页插件来:分页查询")
    public Result pageUsersPlus(
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize){
        //分页的业务
        List<User> data = userService.pageUsersPlus(currentPage,pageSize);
        return Result.ok(data);
    }
}
